#!/bin/bash

# 腾讯云环境准备脚本
echo "开始准备腾讯云部署环境..."

# 安装Docker
if ! command -v docker &> /dev/null; then
    echo "安装Docker..."
    curl -fsSL https://get.docker.com | bash
    systemctl start docker
    systemctl enable docker
fi

# 安装Docker Compose
if ! command -v docker-compose &> /dev/null; then
    echo "安装Docker Compose..."
    curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
fi

# 安装Java
if ! command -v java &> /dev/null; then
    echo "安装Java 8..."
    yum install -y java-1.8.0-openjdk-devel || apt-get install -y openjdk-8-jdk
fi

# 安装Node.js
if ! command -v node &> /dev/null; then
    echo "安装Node.js 16..."
    curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
    apt-get install -y nodejs || yum install -y nodejs
fi

# 安装Maven
if ! command -v mvn &> /dev/null; then
    echo "安装Maven..."
    wget https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
    tar -xzf apache-maven-3.8.6-bin.tar.gz -C /opt
    ln -s /opt/apache-maven-3.8.6/bin/mvn /usr/local/bin/mvn
fi

# 创建项目目录
mkdir -p /opt/bi-platform
mkdir -p /data/mysql
mkdir -p /data/redis
mkdir -p /data/elasticsearch

echo "环境准备完成！"
echo "请将项目文件上传到 /opt/bi-platform 目录"
echo "然后运行: cd /opt/bi-platform && docker-compose up -d"